<?php

namespace Trawind\Events\Subscribers\Inventory\Receipt;

use Trawind\Events\Events\Inventory\Receipt\DeleteReceiptEvent;
use Trawind\Extension\Models\Deploy\BusinessType;

class PutawaySubscriber
{
    private $businessType = \Trawind\Basics\Enums\BusinessType::INVENTORY_RECEIPT_PUTAWAY;
    
    public function deleteReceipt($event)
    {
        if ($this->businessType == $event->payload['business_type_id']) {
            $repository = BusinessType::getEloquentById($this->businessType);
            $repository->callback($event->payload, DeleteReceiptEvent::class);
        }
    }

    /**
     *
     * @param  \Illuminate\Events\Dispatcher  $events
     */
    public function subscribe($events)
    {
        $events->listen(
            DeletePutawayEvent::class,
            static::class . '@deletePutaway'
        );
    }
}
